import pymysql
import hashlib
conn = pymysql.connect(host='120.78.6.253',port=3306,user='root',password='123456',db='bbs',charset='utf8')
while True:
    name = input('用户名:')
    if len(name) > 2:
        break
    else:
        print('输入用户名有误')
pwd = input('输入密码:')
pwd = hashlib.sha1(pwd.encode("utf8")).hexdigest()
print(pwd)
try:
    cursor = conn.cursor()
    sql = "insert into user1(username,password) values(%s,%s)"
    res = [name,pwd]
    print(res)
    cursor.execute(sql,res)
    conn.commit()
    cursor.close()
    conn.close()
except Exception as e:
    print(e)
else:
    print('创建成功')
